package logic

import (
	"context"
	"fmt"
	"gorm.io/gorm"
	"hotel/models/mysql"

	"hotel/hotelrpc/hotelrpc"
	"hotel/hotelrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PerfectHotelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPerfectHotelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerfectHotelLogic {
	return &PerfectHotelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PerfectHotelLogic) PerfectHotel(in *hotelrpc.PerfectHotelRequest) (*hotelrpc.PerfectHotelResponse, error) {
	// todo: add your logic here and delete this line
	var person mysql.Person
	mysql.Db.Debug().Where("id = ?", in.Id).Find(&person)
	if person.ID == 0 {
		return nil, fmt.Errorf("完善的用户不存在")
	}
	m := mysql.Person{
		Model:    gorm.Model{ID: uint(in.Id)},
		Avatar:   in.Avatar,
		Name:     in.Name,
		Gender:   in.Gender,
		Nickname: in.Nickname,
		Self:     in.Self,
	}
	mysql.Db.Debug().Model(&m).Updates(&m)
	return &hotelrpc.PerfectHotelResponse{Id: int64(m.ID)}, nil
}
